package com.rui.cn.provider.service.system.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rui.cn.entity.system.SysRolePermission;
import com.rui.cn.provider.repository.system.SysRolePermissionDao;
import com.rui.cn.provider.service.system.SysRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 用户角色 服务实现类
 * </p>
 *
 * @author zhang123
 * @since 2018-01-14
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysRolePermissionServiceImpl extends ServiceImpl<SysRolePermissionDao,SysRolePermission> implements SysRolePermissionService {
    @Autowired
    private  SysRolePermissionDao sysRolePermissionDao;
    @Override
    public Integer saveRolePermiss(Integer[] ids, Integer roleid) {
        Integer flag=0;
        //先删除角色的所有权限
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("roleid",roleid);
        sysRolePermissionDao.deleteByMap(map);
        for (Integer pid:ids){
            if (pid==0){
                flag++;
                continue;
            }
            flag+=sysRolePermissionDao.insert(new SysRolePermission(roleid,pid));
        }
        return flag;
    }
}
